package com.zp.base.controller;

import com.zp.base.entity.bo.OperationDiagnosisConfigBo;
import com.zp.base.entity.vo.OperationDiagnosisConfigVo;
import com.zp.base.service.IOperationDiagnosisConfigService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 诊断类型、手术字典类型配置控制器
 * 前端访问路由地址为:/base/operationDiagnosisConfig
 *
 * @author zhang peng
 * @date 2023-01-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/operationDiagnosisConfig")
public class OperationDiagnosisConfigController extends BaseController {

    private final IOperationDiagnosisConfigService iOperationDiagnosisConfigService;

    /**
     * 查询诊断类型、手术字典类型配置列表 (分页)
     */
//    @SaCheckPermission("base:operationDiagnosisConfig:list")
    @GetMapping("/selectPage")
    public TableDataInfo<OperationDiagnosisConfigVo> selectPage (OperationDiagnosisConfigBo bo, PageQuery pageQuery) {
        return iOperationDiagnosisConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询诊断类型、手术字典类型配置列表 (不分页)
     */
//    @SaCheckPermission("base:operationDiagnosisConfig:list")
    @GetMapping("/list")
    public R<List<OperationDiagnosisConfigVo>> list (OperationDiagnosisConfigBo bo) {
        List<OperationDiagnosisConfigVo> list = iOperationDiagnosisConfigService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出诊断类型、手术字典类型配置列表
     */
//    @SaCheckPermission("base:operationDiagnosisConfig:export")
    @Log(title = "诊断类型、手术字典类型配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (OperationDiagnosisConfigBo bo, HttpServletResponse response) {
        List<OperationDiagnosisConfigVo> list = iOperationDiagnosisConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "诊断类型、手术字典类型配置", OperationDiagnosisConfigVo.class, response);
    }

    /**
     * 获取诊断类型、手术字典类型配置详细信息
     *
     * @param orgId 主键
     */
//    @SaCheckPermission("base:operationDiagnosisConfig:query")
    @GetMapping("/{orgId}")
    public R<OperationDiagnosisConfigVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String orgId) {
        return R.ok(iOperationDiagnosisConfigService.queryById(orgId));
    }

    /**
     * 新增诊断类型、手术字典类型配置
     */
//    @SaCheckPermission("base:operationDiagnosisConfig:add")
    @Log(title = "诊断类型、手术字典类型配置", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody OperationDiagnosisConfigBo bo) {
        return toAjax(iOperationDiagnosisConfigService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改诊断类型、手术字典类型配置
     */
//    @SaCheckPermission("base:operationDiagnosisConfig:edit")
    @Log(title = "诊断类型、手术字典类型配置", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody OperationDiagnosisConfigBo bo) {
        return toAjax(iOperationDiagnosisConfigService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除诊断类型、手术字典类型配置
     *
     * @param orgIds 主键串
     */
//    @SaCheckPermission("base:operationDiagnosisConfig:remove")
    @Log(title = "诊断类型、手术字典类型配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orgIds}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] orgIds) {
        return toAjax(iOperationDiagnosisConfigService.deleteWithValidByIds(Arrays.asList(orgIds), true) ? 1 : 0);
    }
}
